package com.example.actuator.endpoint;

import com.example.actuator.common.properties.MyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

//(GET) http://localhost:8080/actuator/customProperties
//(POST) http://localhost:8080/actuator/customProperties?val1=abcd&val2=wxyz
@Component
@Endpoint(id="customProperties")
public class CustomPropertiesEndpoint {

    @Autowired
    private MyProperties myProperties;

    @ReadOperation
    public MyProperties customEndPointRead() {
        System.out.println(myProperties);
        return myProperties;
    }

    @WriteOperation
    public String customEndPointWrite(String val1, String val2) {
        myProperties.setVal1(val1);
        myProperties.setVal2(val2);
        return "success: " + myProperties;
    }
}
